<script setup>
import FirstTitle from "@comp/FirstTitle";
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
import { onMounted } from "vue";
import { searchDataRyfh } from "@/api/search";
import { addOrUpdateRyfh } from "@/api/addOrUpdate";

const city = window.globalObj.name;
const editorRef = shallowRef();

const toolbarConfig = {};
const editorConfig = {
  placeholder: "请输入内容...",
};
const mode = ref("default");

// 加载html
const initHtml = () => {
  searchDataRyfh({ m: "行动要点-医疗救护行动" }).then((res) => {
    const { data } = res;
    valueHtml.value = data.find((x) => x.k === "医疗救护行动")?.v || "";
  });
};

const handleCreated = (editor) => {
  editorRef.value = editor; // 记录 editor 实例，重要！
};

const valueHtml = ref(
  "行动时机：当组织人员疏散时，按预案沿途建立医疗救护点，随时担负医疗救护任务；当组织人员掩蔽时，迅速启动人防工程内的救护所，随时担负救护任务；当遭到空袭时，组织医疗救护专业队，组织实时救治任务。<br/>主要对象：疏散掩蔽时，突发疾病或受伤需要救助人员。<br/>行动方法：定点救护与伴随救护相结合。组织医疗救护组在遭敌空袭现场寻找、运送和隐蔽伤病员；按照救治范围对伤员及时急救，做好群众的自救互救指导工作，迅速转送伤病员；做好负责区内的卫生管理和防病工作；请领分发急救药品等。<br/>救护规模比例：XX%，救护规模数量为XX万人。"
);

const saveProgramme = () => {
  ElMessageBox.confirm(`确定要保存吗?`, "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
    customClass: "message-box",
  }).then(() => {
    addOrUpdateRyfh({
      m: "行动要点-医疗救护行动",
      data: [
        {
          k: "医疗救护行动",
          v: valueHtml.value,
        },
      ],
    })
      .then(() => {
        ElMessage.success("操作成功");
      })
      .catch(() => {});
  });
};

onMounted(() => {
  initHtml();
});
onBeforeUnmount(() => {
  const editor = editorRef.value;
  if (!editor) return;
  editor.destroy();
});
</script>
<template>
  <div class="">
    <FirstTitle name="医疗救护行动" />
    <div style="border: 1px solid #ccc" class="top-15">
      <Toolbar
        style="border-bottom: 1px solid #ccc"
        :editor="editorRef"
        :defaultConfig="toolbarConfig"
        :mode="mode"
      />
      <Editor
        style="height: 500px; overflow-y: hidden"
        v-model="valueHtml"
        :defaultConfig="editorConfig"
        :mode="mode"
        @onCreated="handleCreated"
      />
    </div>

    <div class="flex-justify-end top-20">
      <el-button type="primary" class="save-btn" @click="saveProgramme"
        >保存</el-button
      >
    </div>
  </div>
</template>
<style scoped lang="scss"></style>